package bb.lanxing.lib.kt;

//import com.easemob.chat.MessageEncoder;
//import bb.lanxing.lib.devices.sprint.ymodem.YModems;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import kotlin.Metadata;
import kotlin.collections.ArraysKt;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.CharsKt;
import kotlin.text.StringsKt;

public final class ByteArrayExtKt {
    public static String toHexString(byte[] bArr, boolean z) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
//        return ArraysKt.joinToString(bArr, (CharSequence) "", (CharSequence) null, (CharSequence) null, 0, (CharSequence) null, /*(Function1) new ByteArrayExtKt$toHexString$1(z)*/null, 30, (Object) null);
        return null;
    }

    public static String toHexString(byte[] bArr, boolean z, int i, Object obj) {
        if ((i & 1) != 0) {
            z = true;
        }
        return toHexString(bArr, z);
    }

    public static String toAsciiString(byte[] bArr, boolean z, int i, Object obj) {
        if ((i & 1) != 0) {
            z = false;
        }
        return toAsciiString(bArr, z);
    }

    public static int readInt8(byte[] bArr, int i, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        return readInt8(bArr, i);
    }

    public static int readInt8(byte[] bArr, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 1, 0, 8, null);
        return bArr[i];
    }

    public static int readUInt8(byte[] bArr, int i, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        return readUInt8(bArr, i);
    }

    public static int readUInt8(byte[] bArr, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 1, 0, 8, null);
        return bArr[i] & 255;
    }

    public static int readInt16BE(byte[] bArr, int i, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        return readInt16BE(bArr, i);
    }

    public static int readInt16BE(byte[] bArr, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 2, 0, 8, null);
        return (bArr[i] << 8) + (bArr[i + 1] & 255);
    }

    public static int readUInt16BE(byte[] bArr, int i, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        return readUInt16BE(bArr, i);
    }

    public static int readUInt16BE(byte[] bArr, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 2, 0, 8, null);
        return (bArr[i + 1] & 255) | ((bArr[i] & 255) << 8);
    }

    public static int readInt16LE(byte[] bArr, int i, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        return readInt16LE(bArr, i);
    }

    public static int readInt16LE(byte[] bArr, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 2, 0, 8, null);
        return (bArr[i + 1] << 8) + (bArr[i] & 255);
    }

    public static int readUInt16LE(byte[] bArr, int i, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        return readUInt16LE(bArr, i);
    }

    public static int readUInt16LE(byte[] bArr, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 2, 0, 8, null);
        return (bArr[i] & 255) | ((bArr[i + 1] & 255) << 8);
    }

    public static int readInt32BE(byte[] bArr, int i, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        return readInt32BE(bArr, i);
    }

    public static int readInt32BE(byte[] bArr, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 4, 0, 8, null);
        return (bArr[i + 3] & 255) | (bArr[i] << /*YModems.CAN*/24) | ((bArr[i + 1] & 255) << 16) | ((bArr[i + 2] & 255) << 8);
    }

    public static long readUInt32BE(byte[] bArr, int i, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        return readUInt32BE(bArr, i);
    }

    public static long readUInt32BE(byte[] bArr, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 4, 0, 8, null);
        return (bArr[i + 3] & 255) | ((long) (bArr[i] & 255) << 24) | ((bArr[i + 1] & 255) << 16) | ((bArr[i + 2] & 255) << 8);
    }

    public static int readInt32LE(byte[] bArr, int i, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        return readInt32LE(bArr, i);
    }

    public static int readInt32LE(byte[] bArr, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 4, 0, 8, null);
        return (bArr[i] & 255) | (bArr[i + 3] << /*YModems.CAN*/24) | ((bArr[i + 2] & 255) << 16) | ((bArr[i + 1] & 255) << 8);
    }

    public static long readUInt32LE(byte[] bArr, int i, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        return readUInt32LE(bArr, i);
    }

    public static long readUInt32LE(byte[] bArr, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 4, 0, 8, null);
        return (bArr[i] & 255) | ((long) (bArr[i + 3] & 255) << 24) | ((bArr[i + 2] & 255) << 16) | ((bArr[i + 1] & 255) << 8);
    }

    public static long readUInt24LE(byte[] bArr, int i, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        return readUInt24LE(bArr, i);
    }

    public static long readUInt24LE(byte[] bArr, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 4, 0, 8, null);
        return (bArr[i] & 255) | ((bArr[i + 2] & 255) << 16) | ((bArr[i + 1] & 255) << 8);
    }

    public static float readFloatBE(byte[] bArr, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        return Float.intBitsToFloat(readInt32BE(bArr, i));
    }

    public static float readFloatBE(byte[] bArr, int i, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        return readFloatBE(bArr, i);
    }

    public static float readFloatLE(byte[] bArr, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        return Float.intBitsToFloat(readInt32LE(bArr, i));
    }

    public static float readFloatLE(byte[] bArr, int i, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        return readFloatLE(bArr, i);
    }

    public static String readTimeBE(byte[] bArr, int i, String str, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        if ((i2 & 2) != 0) {
            str = "yyyy-MM-dd HH:mm:ss";
        }
        return readTimeBE(bArr, i, str);
    }

    public static String readTimeBE(byte[] bArr, int i, String pattern) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        Intrinsics.checkNotNullParameter(pattern, "pattern");
        return new SimpleDateFormat(pattern).format(readUInt32BE(bArr, i) * 1000);
    }

    public static String readTimeLE(byte[] bArr, int i, String str, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 0;
        }
        if ((i2 & 2) != 0) {
            str = "yyyy-MM-dd HH:mm:ss";
        }
        return readTimeLE(bArr, i, str);
    }

    public static String readTimeLE(byte[] bArr, int i, String pattern) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        Intrinsics.checkNotNullParameter(pattern, "pattern");
        return new SimpleDateFormat(pattern).format(readUInt32LE(bArr, i) * 1000);
    }

    public static byte[] readByteArrayBE(byte[] bArr, int i, int i2) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 0, 0, 12, null);
        int i3 = i2 + i;
        if (i3 > bArr.length) {
            i3 = bArr.length;
        }
        return ArraysKt.copyOfRange(bArr, i, i3);
    }

    public static byte[] readByteArrayLE(byte[] bArr, int i, int i2) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 0, 0, 12, null);
        return ArraysKt.reversedArray(readByteArrayBE(bArr, i, i2));
    }

    public static String readStringBE(byte[] bArr, int i, int i2, String str, boolean z, int i3, Object obj) {
        if ((i3 & 4) != 0) {
            str = "hex";
        }
        if ((i3 & 8) != 0) {
            String lowerCase = str.toLowerCase();
            Intrinsics.checkNotNullExpressionValue(lowerCase, "this as java.lang.String).toLowerCase()");
            z = Intrinsics.areEqual(lowerCase, "hex");
        }
        return readStringBE(bArr, i, i2, str, z);
    }

    public static String readStringBE(byte[] bArr, int i, int i2, String encoding, boolean z) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        Intrinsics.checkNotNullParameter(encoding, "encoding");
        String lowerCase = encoding.toLowerCase();
        Intrinsics.checkNotNullExpressionValue(lowerCase, "this as java.lang.String).toLowerCase()");
        String str = "";
        if (Intrinsics.areEqual(lowerCase, "hex")) {
            return toHexString(readByteArrayBE(bArr, i, i2), z);
        }
        if (!Intrinsics.areEqual(lowerCase, "ascii")) {
            return str;
        }
        byte[] readByteArrayBE = readByteArrayBE(bArr, i, i2);
        ArrayList arrayList = new ArrayList(readByteArrayBE.length);
        for (byte b : readByteArrayBE) {
            arrayList.add((char) b);
        }
        ArrayList arrayList2 = arrayList;
        if (z) {
            str = " ";
        }
//        return CollectionsKt.joinToString(arrayList2, str, null, null, 0, null, null, 62, null);
        return null;
    }

    public static String readStringLE(byte[] bArr, int i, int i2, String str, boolean z, int i3, Object obj) {
        if ((i3 & 4) != 0) {
            str = "hex";
        }
        if ((i3 & 8) != 0) {
            String lowerCase = str.toLowerCase();
            Intrinsics.checkNotNullExpressionValue(lowerCase, "this as java.lang.String).toLowerCase()");
            z = Intrinsics.areEqual(lowerCase, "hex");
        }
        return readStringLE(bArr, i, i2, str, z);
    }

    public static String readStringLE(byte[] bArr, int i, int i2, String encoding, boolean z) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        Intrinsics.checkNotNullParameter(encoding, "encoding");
        String lowerCase = encoding.toLowerCase();
        Intrinsics.checkNotNullExpressionValue(lowerCase, "this as java.lang.String).toLowerCase()");
        String str = "";
        if (Intrinsics.areEqual(lowerCase, "hex")) {
            return toHexString(readByteArrayLE(bArr, i, i2), z);
        }
        if (!Intrinsics.areEqual(lowerCase, "ascii")) {
            return str;
        }
        byte[] readByteArrayLE = readByteArrayLE(bArr, i, i2);
        ArrayList arrayList = new ArrayList(readByteArrayLE.length);
        for (byte b : readByteArrayLE) {
            arrayList.add((char) b);
        }
        ArrayList arrayList2 = arrayList;
        if (z) {
            str = " ";
        }
//        return CollectionsKt.joinToString(arrayList2, str, null, null, 0, null, null, 62, null);
        return null;
    }

    public static byte[] writeInt8(byte[] bArr, int i, int i2, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            i2 = 0;
        }
        return writeInt8(bArr, i, i2);
    }

    public static byte[] writeInt8(byte[] bArr, int i, int i2) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i2, 0, 0, 12, null);
        bArr[i2] = (byte) i;
        return bArr;
    }

    public static byte[] writeInt16BE(byte[] bArr, int i, int i2, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            i2 = 0;
        }
        return writeInt16BE(bArr, i, i2);
    }

    public static byte[] writeInt16BE(byte[] bArr, int i, int i2) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i2, 2, 0, 8, null);
        bArr[i2] = (byte) ((65280 & i) >>> 8);
        bArr[i2 + 1] = (byte) (i & 255);
        return bArr;
    }

    public static byte[] writeInt16LE(byte[] bArr, int i, int i2, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            i2 = 0;
        }
        return writeInt16LE(bArr, i, i2);
    }

    public static byte[] writeInt16LE(byte[] bArr, int i, int i2) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i2, 2, 0, 8, null);
        bArr[i2] = (byte) (i & 255);
        bArr[i2 + 1] = (byte) ((i & 65280) >>> 8);
        return bArr;
    }

    public static byte[] writeInt32BE(byte[] bArr, long j, int i, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            i = 0;
        }
        return writeInt32BE(bArr, j, i);
    }

    public static byte[] writeInt32BE(byte[] bArr, long j, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 4, 0, 8, null);
        bArr[i + 3] = (byte) (255 & j);
        bArr[i + 2] = (byte) ((65280 & j) >>> 8);
        bArr[i + 1] = (byte) ((16711680 & j) >>> 16);
        bArr[i] = (byte) ((j & 4278190080L) >>> 24);
        return bArr;
    }

    public static byte[] writeInt32LE(byte[] bArr, long j, int i, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            i = 0;
        }
        return writeInt32LE(bArr, j, i);
    }

    public static byte[] writeInt32LE(byte[] bArr, long j, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 4, 0, 8, null);
        bArr[i] = (byte) (255 & j);
        bArr[i + 1] = (byte) ((65280 & j) >>> 8);
        bArr[i + 2] = (byte) ((16711680 & j) >>> 16);
        bArr[i + 3] = (byte) ((j & 4278190080L) >>> 24);
        return bArr;
    }

    public static byte[] writeFloatBE(byte[] bArr, float f, int i, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            i = 0;
        }
        return writeFloatBE(bArr, f, i);
    }

    public static byte[] writeFloatBE(byte[] bArr, float f, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 4, 0, 8, null);
        writeInt32BE(bArr, Float.floatToIntBits(f), i);
        return bArr;
    }

    public static byte[] writeFloatLE(byte[] bArr, float f, int i, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            i = 0;
        }
        return writeFloatLE(bArr, f, i);
    }

    public static byte[] writeFloatLE(byte[] bArr, float f, int i) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        throwOffsetError(bArr, i, 4, 0, 8, null);
        writeInt32LE(bArr, Float.floatToIntBits(f), i);
        return bArr;
    }

    public static byte[] writeTimeBE(byte[] bArr, String str, int i, String str2, int i2, Object obj) throws ParseException {
        if ((i2 & 2) != 0) {
            i = 0;
        }
        if ((i2 & 4) != 0) {
            str2 = "yyyy-MM-dd HH:mm:ss";
        }
        return writeTimeBE(bArr, str, i, str2);
    }

    public static byte[] writeTimeBE(byte[] bArr, String time, int i, String pattern) throws ParseException {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        Intrinsics.checkNotNullParameter(time, "time");
        Intrinsics.checkNotNullParameter(pattern, "pattern");
        writeInt32BE(bArr, new SimpleDateFormat(pattern).parse(time).getTime() / 1000, i);
        return bArr;
    }

    public static byte[] writeTimeLE(byte[] bArr, String str, int i, String str2, int i2, Object obj) throws ParseException {
        if ((i2 & 2) != 0) {
            i = 0;
        }
        if ((i2 & 4) != 0) {
            str2 = "yyyy-MM-dd HH:mm:ss";
        }
        return writeTimeLE(bArr, str, i, str2);
    }

    public static byte[] writeTimeLE(byte[] bArr, String time, int i, String pattern) throws ParseException {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        Intrinsics.checkNotNullParameter(time, "time");
        Intrinsics.checkNotNullParameter(pattern, "pattern");
        writeInt32LE(bArr, new SimpleDateFormat(pattern).parse(time).getTime() / 1000, i);
        return bArr;
    }

    public static byte[] writeByteArrayBE(byte[] bArr, byte[] bArr2, int i, int i2, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            i = 0;
        }
        if ((i3 & 4) != 0) {
            i2 = bArr2.length;
        }
        return writeByteArrayBE(bArr, bArr2, i, i2);
    }

    public static byte[] writeByteArrayBE(byte[] bArr, byte[] byteArray, int i, int i2) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        Intrinsics.checkNotNullParameter(byteArray, "byteArray");
        writeStringBE(bArr, toHexString(byteArray, false, 1, null), i, i2, null, 8, null);
        return bArr;
    }

    public static byte[] writeByteArrayLE(byte[] bArr, byte[] bArr2, int i, int i2, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            i = 0;
        }
        if ((i3 & 4) != 0) {
            i2 = bArr2.length;
        }
        return writeByteArrayLE(bArr, bArr2, i, i2);
    }

    public static byte[] writeByteArrayLE(byte[] bArr, byte[] byteArray, int i, int i2) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        Intrinsics.checkNotNullParameter(byteArray, "byteArray");
        writeStringLE(bArr, toHexString(byteArray, false, 1, null), i, i2, null, 8, null);
        return bArr;
    }

    public static byte[] insertByteArrayBE(byte[] bArr, byte[] bArr2, int i, int i2, int i3, int i4, Object obj) {
        if ((i4 & 2) != 0) {
            i = 0;
        }
        if ((i4 & 4) != 0) {
            i2 = 0;
        }
        if ((i4 & 8) != 0) {
            i3 = bArr2.length - i2;
        }
        return insertByteArrayBE(bArr, bArr2, i, i2, i3);
    }

    public static byte[] insertByteArrayBE(byte[] bArr, byte[] insertArray, int i, int i2, int i3) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        Intrinsics.checkNotNullParameter(insertArray, "insertArray");
        byte[] copyOfRange = ArraysKt.copyOfRange(bArr, 0, i);
        return ArraysKt.plus(ArraysKt.plus(copyOfRange, ArraysKt.copyOfRange(insertArray, i2, i3 + i2)), ArraysKt.copyOfRange(bArr, i, bArr.length));
    }

    public static byte[] insertByteArrayLE(byte[] bArr, byte[] bArr2, int i, int i2, int i3, int i4, Object obj) {
        if ((i4 & 2) != 0) {
            i = 0;
        }
        if ((i4 & 4) != 0) {
            i2 = 0;
        }
        if ((i4 & 8) != 0) {
            i3 = bArr2.length - i2;
        }
        return insertByteArrayLE(bArr, bArr2, i, i2, i3);
    }

    public static byte[] insertByteArrayLE(byte[] bArr, byte[] insertArray, int i, int i2, int i3) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        Intrinsics.checkNotNullParameter(insertArray, "insertArray");
        ArraysKt.reverse(insertArray);
        byte[] copyOfRange = ArraysKt.copyOfRange(bArr, 0, i);
        return ArraysKt.plus(ArraysKt.plus(copyOfRange, ArraysKt.copyOfRange(insertArray, i2, i3 + i2)), ArraysKt.copyOfRange(bArr, i, bArr.length));
    }

    public static byte[] writeStringBE(byte[] bArr, String str, int i, String str2, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            i = 0;
        }
        if ((i2 & 4) != 0) {
            str2 = "hex";
        }
        return writeStringBE(bArr, str, i, str2);
    }

    public static byte[] writeStringBE(byte[] bArr, String str, int i, String encoding) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        Intrinsics.checkNotNullParameter(str, "str");
        Intrinsics.checkNotNullParameter(encoding, "encoding");
        int i2 = 0;
        throwOffsetError(bArr, i, 0, 0, 12, null);
        String lowerCase = encoding.toLowerCase();
        Intrinsics.checkNotNullExpressionValue(lowerCase, "this as java.lang.String).toLowerCase()");
        if (Intrinsics.areEqual(lowerCase, "hex")) {
            String replace = str;//StringsKt.replace(str, " ", "", false, 4, (Object) null);
            throwHexError(replace);
            int length = replace.length() / 2;
            while (i2 < length) {
                int i3 = i2 + i;
                if (i3 < bArr.length) {
                    int i4 = i2 * 2;
                    String substring = replace.substring(i4, i4 + 2);
                    Intrinsics.checkNotNullExpressionValue(substring, "this as java.lang.String…ing(startIndex, endIndex)");
                    bArr[i3] = (byte) Integer.parseInt(substring, CharsKt.checkRadix(16));
                }
                i2++;
            }
        } else if (Intrinsics.areEqual(lowerCase, "ascii")) {
            char[] charArray = str.toCharArray();
            Intrinsics.checkNotNullExpressionValue(charArray, "this as java.lang.String).toCharArray()");
            ArrayList arrayList = new ArrayList(charArray.length);
            int length2 = charArray.length;
            while (i2 < length2) {
                arrayList.add((int) charArray[i2]);
                i2++;
            }
            ArrayList<Number> arrayList2 = arrayList;
            ArrayList arrayList3 = new ArrayList(CollectionsKt.collectionSizeOrDefault(arrayList2, 10));
            for (Number number : arrayList2) {
                String num = Integer.toString(number.intValue(), CharsKt.checkRadix(16));
                Intrinsics.checkNotNullExpressionValue(num, "toString(this, checkRadix(radix))");
                arrayList3.add(num);
            }
//            writeStringBE(bArr, CollectionsKt.joinToString(arrayList3, "", null, null, 0, null, null, 62, null), i, "hex");
        }
        return bArr;
    }

    public static byte[] writeStringLE(byte[] bArr, String str, int i, String str2, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            i = 0;
        }
        if ((i2 & 4) != 0) {
            str2 = "hex";
        }
        return writeStringLE(bArr, str, i, str2);
    }

    public static byte[] writeStringLE(byte[] bArr, String str, int i, String encoding) {
        String lowerCase = encoding.toLowerCase();
        if (Intrinsics.areEqual(lowerCase, "hex")) {
            writeStringBE(bArr, StringExtKt.reversalEvery2Charts(str, false, 1, null), i, encoding);
        } else if (Intrinsics.areEqual(lowerCase, "ascii")) {
            char[] charArray = str.toCharArray();
            ArrayList arrayList = new ArrayList(charArray.length);
            for (char c : charArray) {
                arrayList.add((int) c);
            }
            ArrayList<Number> arrayList2 = arrayList;
            ArrayList arrayList3 = new ArrayList(CollectionsKt.collectionSizeOrDefault(arrayList2, 10));
            for (Number number : arrayList2) {
                String num = Integer.toString(number.intValue(), CharsKt.checkRadix(16));
                arrayList3.add(num);
            }
//            writeStringLE(bArr, CollectionsKt.joinToString(arrayList3, "", null, null, 0, null, null, 62, null), i, "hex");
        }
        return bArr;
    }

    public static byte[] writeStringBE(byte[] bArr, String str, int i, int i2, String str2, int i3, Object obj) {
        if ((i3 & 8) != 0) {
            str2 = "hex";
        }
        return writeStringBE(bArr, str, i, i2, str2);
    }

    public static byte[] writeStringBE(byte[] bArr, String str, int i, int i2, String encoding) {
        throwOffsetError(bArr, i, i2, 0, 8, null);
        String lowerCase = encoding.toLowerCase();
        if (Intrinsics.areEqual(lowerCase, "hex")) {
            int i3 = i2 * 2;
            String substring = str;//StringsKt.padStart(StringsKt.replace(str, " ", "", false, 4, (Object) null), i3, '0').substring(0, i3);
            Intrinsics.checkNotNullExpressionValue(substring, "this as java.lang.String…ing(startIndex, endIndex)");
            throwHexError(substring);
            writeStringBE(bArr, substring, i, null, 4, null);
        } else if (Intrinsics.areEqual(lowerCase, "ascii")) {
            char[] charArray = str.toCharArray();
            ArrayList arrayList = new ArrayList(charArray.length);
            for (char c : charArray) {
                arrayList.add((int) c);
            }
            ArrayList<Number> arrayList2 = arrayList;
            ArrayList arrayList3 = new ArrayList(CollectionsKt.collectionSizeOrDefault(arrayList2, 10));
            for (Number number : arrayList2) {
                String num = Integer.toString(number.intValue(), CharsKt.checkRadix(16));
                arrayList3.add(num);
            }
//            writeStringBE(bArr, CollectionsKt.joinToString(arrayList3, "", null, null, 0, null, null, 62, null), i, i2, "hex");
        }
        return bArr;
    }

    public static byte[] writeStringLE(byte[] bArr, String str, int i, int i2, String str2, int i3, Object obj) {
        if ((i3 & 8) != 0) {
            str2 = "hex";
        }
        return writeStringLE(bArr, str, i, i2, str2);
    }

    public static byte[] writeStringLE(byte[] bArr, String str, int i, int i2, String encoding) {
        String lowerCase = encoding.toLowerCase();
        if (Intrinsics.areEqual(lowerCase, "hex")) {
            int i3 = i2 * 2;
            String substring = StringsKt.padEnd(StringExtKt.reversalEvery2Charts(str, false, 1, null), i3, '0').substring(0, i3);
            writeStringBE(bArr, substring, i, i2, encoding);
        } else if (Intrinsics.areEqual(lowerCase, "ascii")) {
            char[] charArray = str.toCharArray();
            ArrayList arrayList = new ArrayList(charArray.length);
            for (char c : charArray) {
                arrayList.add((int) c);
            }
            ArrayList<Number> arrayList2 = arrayList;
            ArrayList arrayList3 = new ArrayList(CollectionsKt.collectionSizeOrDefault(arrayList2, 10));
            for (Number number : arrayList2) {
                String num = Integer.toString(number.intValue(), CharsKt.checkRadix(16));
                arrayList3.add(num);
            }
//            writeStringLE(bArr, CollectionsKt.joinToString(arrayList3, "", null, null, 0, null, null, 62, null), i, i2, "hex");
        }
        return bArr;
    }

    private static long readUnsigned(byte[] bArr, int i, int i2, boolean z) {
        long j = 0;
        for (int i3 = 0; i3 < i; i3++) {
            int i4 = (z ? i3 : (i - 1) - i3) << 3;
            j |= (255L << i4) & ((long) bArr[i2 + i3] << i4);
        }
        return j;
    }

    private static void throwLenError(byte[] bArr, int i) {
        if (i <= 0 || i > 4) {
            throw new IllegalArgumentException("The value of \"byteLength\" is out of range. It must be >= 1 and <= 4. Received " + i);
        } else if (i > bArr.length) {
            throw new IllegalArgumentException("Attempt to write outside ByteArray bounds.");
        }
    }

    private static void throwHexError(String str) {
        if (str.length() % 2 == 0) {
            return;
        }
        throw new IllegalArgumentException("The value of \"hex\".length is out of range. It must be an even number");
    }

    static void throwOffsetError(byte[] bArr, int i, int i2, int i3, int i4, Object obj) {
        if ((i4 & 4) != 0) {
            i2 = 1;
        }
        if ((i4 & 8) != 0) {
            i3 = 0;
        }
        throwOffsetError(bArr, i, i2, i3);
    }

    private static void throwOffsetError(byte[] bArr, int i, int i2, int i3) {
        if (i <= (bArr.length - i2) - i3) {
            return;
        }
        throw new IllegalArgumentException("The value of \"offset\" is out of range. It must be >= 0 and <= " + ((bArr.length - i2) - i3) + ". Received " + i);
    }

    public static String toAsciiString(byte[] bArr, boolean z) {
        Intrinsics.checkNotNullParameter(bArr, "<this>");
        ArrayList arrayList = new ArrayList(bArr.length);
        for (byte b : bArr) {
            arrayList.add((char) b);
        }
//        return CollectionsKt.joinToString(arrayList, z ? " " : "", null, null, 0, null, null, 62, null);
        return null;
    }
}
